package com.ss.android.newmedia.message;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.hardware.display.DisplayManager;
import android.media.AudioManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.support.v4.app.NotificationCompat.Builder;
import android.text.TextUtils;
import android.util.Log;
import android.view.Display;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RemoteViews;
import android.widget.TextView;


import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.common.utility.Logger;
import com.bytedance.frameworks.baselib.network.http.util.TaskInfo;
import com.ss.android.article.browser.R;
import com.ss.android.common.AbsApiThread;
import com.ss.android.common.applog.AppLog;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.util.IdCache;
import com.ss.android.common.util.l;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.common.util.ToolUtils;
import com.ss.android.image.BaseImageManager;
import com.ss.android.image.FrescoUtils;
import com.ss.android.newmedia.MediaAppData;
import com.ss.android.newmedia.a.AdsAppBaseActivity;
import com.ss.android.newmedia.activity.AbsSplashActivity;
import com.ss.android.newmedia.BaseAppData;
import com.ss.android.newmedia.message.a.e;
import com.ss.android.newmedia.message.dialog.w;
import com.ss.android.push.window.oppo.OppoPushWindowManager;
import com.ss.android.push.window.oppo.PushWindowScrollView;
import com.ss.android.push.window.oppo.m;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public final class i {
    private static final Object b;
    private static final List d;
    private static final Comparator g;
    private static boolean a;
    private static NotificationManager c;
    private static volatile boolean e;
    private static WeakHandler f;
    private static Map h;

    static {
        a = true;
        b = new Object();
        d = new ArrayList();
        e = false;
        f = new WeakHandler(Looper.getMainLooper(), new j());
        g = new k();
        h = new HashMap();
    }

    public static void a(Context arg12, String arg13, long arg14, long arg16, boolean arg18, JSONObject[] arg19) {
        if (arg18) {
            if (arg19.length > 0) {
                MobClickCombiner.onEvent(arg12, "client_apn", arg13, arg14, arg16, arg19[0]);
            } else {
                MobClickCombiner.onEvent(arg12, "client_apn", arg13, arg14, arg16);
            }
        } else if (arg19.length > 0) {
            MobClickCombiner.onEvent(arg12, "apn", arg13, arg14, arg16, arg19[0]);
        } else {
            MobClickCombiner.onEvent(arg12, "apn", arg13, arg14, arg16);
        }
    }

    @TargetApi(value = 17)
    public static void a(Context arg14, String arg15, BaseAppData arg16, int arg17, String arg18, boolean arg19) {
        Integer v4_2;
        boolean v5_1;
        JSONObject v2_5 = null;
        h v11;
        int v2_3;
        JSONArray v4_1;
        String v2_2;
        Object v4;
        ArrayList v3;
        try {
            if (android.support.design.a.isTextEmpty(arg15)) {
                return;
            }

            i.c = (NotificationManager) arg14.getSystemService(Context.NOTIFICATION_SERVICE);
            if (i.e) {
            } else {
                v3 = new ArrayList();
                v4 = i.b;
                synchronized (v4) {
                    v2_2 = arg14.getSharedPreferences("app_notify_info", 0).getString("notify_list", null);
                }
                if (android.support.design.a.isTextEmpty(v2_2)) {

                } else {
                    v4_1 = new JSONArray(v2_2);
                    int v5 = v4_1.length();
                    v2_3 = 0;
                    while (true) {
                        if (v2_3 >= v5) {
                            break;
                        }
                        JSONObject v6 = v4_1.getJSONObject(v2_3);
                        long v8 = v6.optLong("time", 0);
                        int v6_1 = v6.optInt("id", 0);
                        if (v6_1 > 0) {
                            ((List) v3).add(new a(v6_1, v8));
                        }
                        ++v2_3;
                        continue;
                    }
                }
                if (((List) v3).isEmpty()) {

                } else {
                    i.d.clear();
                    i.d.addAll(v3);
                }
                i.e = true;
            }
            Logger.d("MessageShowHandler", "message received, msg is: " + arg15);
            l.a();
            v11 = new h(new JSONObject(arg15));
            v11.a = new JSONObject(arg15);
            v11.u = arg19;
            v11.x = arg17;
            v11.y = arg18;
            if (Logger.debug()) {
                Logger.d("PushService MessageShowHandler", v11.a.toString());
            }
            if (TextUtils.isEmpty(v11.j)) {
            } else if (!v11.j.startsWith("http")) {
            } else {
                v2_3 = 4;
                try {
                    String[] v2_4 = new String[v2_3];
                    v2_4[0] = v11.j;
                    v2_4[1] = AppLog.deviceId();
                    v2_4[2] = String.valueOf(v11.i);
                    v2_4[3] = v11.m;
                    com.bytedance.common.utility.b.a.a(new i$d(), ((Object[]) v2_4));
                    v2_5 = new JSONObject();
                    v2_5.put("callback", v11.j);
                    v2_5.put("did", AppLog.deviceId());
                    v2_5.put("id", String.valueOf(v11.i));
                    v2_5.put("url", v11.m);
                    i.a(arg14, "message_callback", ((long) v11.i), ((long) arg17), arg19, new JSONObject[]{v2_5});
                } catch (Exception e) {
                    v2_5 = new JSONObject();
                    v2_5.put("callback", v11.j);
                    v2_5.put("did", AppLog.deviceId());
                    v2_5.put("id", String.valueOf(v11.i));
                    v2_5.put("url", v11.m);
                    i.a(arg14, "message_callback", ((long) v11.i), ((long) arg17), arg19, new JSONObject[]{v2_5});
                }
            }
            JSONObject v3_1 = null;
            JSONObject v10_1;
            try {
                v5_1 = ((PowerManager) arg14.getSystemService(Context.POWER_SERVICE)).isScreenOn();
                v4_2 = Integer.valueOf(-1);
                if (Build.VERSION.SDK_INT >= 20) {
                    Display v2_6 = ((DisplayManager) arg14.getSystemService(Context.DISPLAY_SERVICE)).getDisplay(0);
                    if (v2_6 != null) {
                        Object v2_7 = android.support.design.a.a(Display.class, "getState", new Object[]{v2_6});
                        Integer v2_8;
                        if (!(v2_7 instanceof Integer)) {
                            v2_8 = v4_2;
                        } else {
                            v2_8 = (Integer) v2_7;
                        }
                        boolean v4_3 = Logger.debug();
                        if ((v4_3) && v2_8 != null) {
                            Logger.d("PushService", "displayState = " + v2_8);
                        }
                        v4_2 = v2_8;
                    }
                }

                try {
                    v2_5 = new JSONObject();
                    v2_5.put("interactive_state", v5_1);
                    if (v4_2.intValue() >= 0) {
                        v2_5.put("display_state", v4_2);
                    }

                    if (Logger.debug()) {
                        Logger.d("PushService", "brightness = " + v2_5.toString());
                    }
                    v10_1 = v2_5;
                } catch (Exception v3_2) {
                    v10_1 = v2_5;
                }
            } catch (Exception e) {
                v2_5 = null;
                v10_1 = v2_5;
            }
            try {
                i.a(arg14, "news_achieve", ((long) v11.i), ((long) arg17), arg19, new JSONObject[]{v10_1});
                if (v11.k == 1) {
                    Logger.i("MessageShowHandler", "skip notify for isPing");
                    return;
                }

                if (arg17 == 6) {
                    i.a(arg14, "umeng_news_achieve", ((long) v11.i), ((long) arg17), arg19, new JSONObject[]{v10_1});
                }

                if (v11.b != 0 && v11.c != 0 && (i.a(v11.m, arg16))) {
                    com.ss.android.newmedia.message.b.a(arg14).a(v11.i);
                    i.a(arg14, "news_forbid", ((long) v11.i), 1, false, new JSONObject[0]);
                    Logger.i("MessageShowHandler", "skip notify " + v11.m);
                    new StringBuilder("skip notify ").append(v11.m);
                    l.a();
                    return;
                }

                if (!android.support.design.a.isTextEmpty(v11.d)) {
                    long v2_10 = System.currentTimeMillis();
                    if (v11.b != 0 && v11.c != 0 && !arg19) {
                        long v4_4 = ((long) v11.i);
                        if (Logger.debug()) {
                            Logger.d("PushService MessageShowHandler", "handleMessageExisted");
                        }

                        IdCache.Id v3_3 = BaseAppData.a(v4_4, v2_10);
                        boolean v2_11 = arg16.mNotifyMessage.isIdExist(v3_3);
                        if (v2_11) {
                            IdCache.Id v4_5 = arg16.mNotifyMessage.getId(v3_3);
                            if (v4_5 != null) {
                                if (Logger.debug()) {
                                    Logger.d("PushService MessageShowHandler", " messageId.receive_time - lastMessageId.receive_time = " + String.valueOf(v3_3.time - v4_5.time));
                                }

                                if (v3_3.time - v4_5.time <= 43200000) {
                                } else {
                                    v2_11 = false;
                                }
                            }
                        }
                        Message v4_6 = new Message();
                        v4_6.what = 10010;
                        v4_6.arg1 = 1;
                        v4_6.obj = v3_3;
                        arg16.mWeakHandler.sendMessage(v4_6);
                        if (!v2_11) {
                        } else {
                            if (Logger.debug()) {
                                Logger.d("PushService MessageShowHandler", "drop exist message ");
                            }
                            com.ss.android.newmedia.message.b.a(arg14).a(v11.i);
                            i.a(arg14, "news_forbid", ((long) v11.i), 2, false, new JSONObject[0]);
                            l.a();
                            return;
                        }
                    }

                    if ((i.a) && !android.support.design.a.isTextEmpty(v11.f) && v11.g != 0) {
                        FrescoUtils.load(arg14, Uri.parse(v11.f), new com.ss.android.newmedia.message.l(arg14, arg16, v11));
                    } else {
                        i.b(arg14, arg16, v11, null);
                    }

                    return;
                }

                if (v11.b != 0) {
                    return;
                }

                if (arg14 == null) {
                    return;
                }
                Intent v2_9 = ToolUtils.getLaunchIntentForPackage(arg14, arg14.getPackageName());
                if (v2_9 == null) {
                    return;
                }
                v2_9.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                v2_9.putExtra("from_notification", true);
                arg14.startActivity(v2_9);
                return;
            } catch (Throwable v2_1) {
                v2_1.printStackTrace();
                return;
            }

        } catch (Throwable v2_1) {
        }
    }

    public static void a(Context arg7, BaseAppData arg8, h arg9) {
        if (!i.a || (android.support.design.a.isTextEmpty(arg9.f)) || arg9.g == 0) {
            i.b(arg7, arg8, null, arg9);
        } else {
            if (Logger.debug()) {
                Logger.d("MessageShowHandler", "imageUrl = " + arg9.f + " imageType = " + arg9.g);
            }

            b v6 = new b(arg7, arg8, arg9);
            i.h.put(Integer.valueOf(arg9.i), v6);
            TaskInfo v2 = new TaskInfo();
            BaseImageManager v3 = new BaseImageManager(arg7);
            Resources v0 = arg7.getResources();
            new com.ss.android.newmedia.message.q(arg7, v2, v3, v0.getDimensionPixelSize(R.dimen.j6), v0.getDimensionPixelSize(R.dimen.j5)).a(((ImageView) v6), arg9.f, arg9.f);
        }
    }

    private static Notification a(Context arg8, h arg9, Bitmap arg10) {
        Notification v1_2 = null;
        Builder v2;
        int v0 = 0;
        try {
            if (android.support.design.a.isTextEmpty(arg9.e)) {
                arg9.e = arg8.getString(com.ss.android.article.browser.R.string.dt);
            }

            v2 = new Builder(arg8);
            long v4 = System.currentTimeMillis();
            v2.setTicker(arg9.e).setAutoCancel(true);
            v2.setWhen(v4);
            if (Build.VERSION.SDK_INT > 20) {
                v2.setSmallIcon(com.ss.android.article.browser.R.drawable.uf);
            } else {
                int v1 = R.drawable.m3;
                v2.setSmallIcon(v1);
            }
            if ((arg9.p) && !arg9.a()) {
                v2.setLights(-16711936, 1000, 2500);
            }

            v2.setColor(13882323);
            if (Build.VERSION.SDK_INT > 20 && arg9.l < 2 && !arg9.a()) {
                v2.setPriority(1);
                v2.setVibrate(new long[0]);
            }

            a(arg9, v2);
            if (arg8 == null || arg9 == null) {
                v1_2 = null;
            } else {
                BaseAppData v1_1 = BaseAppData.inst();
                if (Build.VERSION.SDK_INT > 20 && v1_1 != null) {
                    int v1 = v1_1.cx > 0 ? 1 : 0;
                    if (v1 == 0) {
                    } else {
                        v0 = 1;
                    }
                }
                if (v0 != 0) {
                    arg9.t.c %= 10;
                }

                if (arg10 == null) {
                    arg9.t.c = 0;
                }

                String v0_2;
                String v1_3;
                String v3;
                RemoteViews v4_1;

                switch (arg9.t.c) {
                    case 0: {
                        v1_2 = android.support.design.a.a(v2, arg8, arg9.e, arg9.d);
                        break;
                    }
                    case 1: {
                        v1_2 = android.support.design.a.a(v2, arg8, arg9.e, arg9.d, arg10);
                        break;
                    }
                    case 2: {
                        v2.setContentTitle(arg9.e).setContentText(arg9.d).setLargeIcon(arg10);
                        v1_2 = v2.build();
                        break;
                    }
                    case 11: {
                        v0_2 = arg9.e;
                        v1_3 = arg9.d;
                        v3 = arg8.getString(com.ss.android.article.browser.R.string.dt) + " · " + new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis()));
                        v4_1 = new RemoteViews(arg8.getPackageName(), R.layout.gp);
                        v4_1.setTextViewText(com.ss.android.article.browser.R.id.desc, ((CharSequence) v1_3));
                        v4_1.setTextViewText(com.ss.android.article.browser.R.id.a2e, ((CharSequence) v3));
                        v4_1.setImageViewBitmap(com.ss.android.article.browser.R.id.a78, arg10);
                        RemoteViews v5 = new RemoteViews(arg8.getPackageName(), R.layout.gq);
                        v5.setTextViewText(com.ss.android.article.browser.R.id.desc, ((CharSequence) v1_3));
                        v5.setTextViewText(com.ss.android.article.browser.R.id.a2e, ((CharSequence) v3));
                        v5.setImageViewBitmap(com.ss.android.article.browser.R.id.a78, arg10);
                        v2.setContentTitle(((CharSequence) v0_2)).setContentText(((CharSequence) v1_3));
                        v1_2 = v2.build();
                        if (Build.VERSION.SDK_INT >= 16) {
                            v1_2.bigContentView = v4_1;
                        }

                        v1_2.contentView = v5;
                        break;
                    }
                    case 12: {
                        v0_2 = arg9.e;
                        v1_3 = arg9.d;
                        v3 = arg8.getString(com.ss.android.article.browser.R.string.dt) + " · " + new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis()));
                        v4_1 = new RemoteViews(arg8.getPackageName(), R.layout.gq);
                        v4_1.setTextViewText(com.ss.android.article.browser.R.id.desc, ((CharSequence) v1_3));
                        v4_1.setTextViewText(com.ss.android.article.browser.R.id.a2e, ((CharSequence) v3));
                        v4_1.setImageViewBitmap(com.ss.android.article.browser.R.id.a78, arg10);
                        v2.setContentTitle(((CharSequence) v0_2)).setContentText(((CharSequence) v1_3));
                        v1_2 = v2.build();
                        v1_2.contentView = v4_1;
                        break;
                    }
                    case 21: {
                        v0_2 = arg9.e;
                        v1_3 = arg9.d;
                        v3 = arg8.getString(com.ss.android.article.browser.R.string.dt) + " · " + new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis()));
                        v4_1 = new RemoteViews(arg8.getPackageName(), R.layout.gr);
                        v4_1.setTextViewText(com.ss.android.article.browser.R.id.desc, ((CharSequence) v1_3));
                        v4_1.setTextViewText(com.ss.android.article.browser.R.id.title, ((CharSequence) v0_2));
                        v4_1.setTextViewText(com.ss.android.article.browser.R.id.a2e, ((CharSequence) v3));
                        v4_1.setImageViewBitmap(com.ss.android.article.browser.R.id.a78, arg10);
                        RemoteViews v5 = new RemoteViews(arg8.getPackageName(), R.layout.gs);
                        v5.setTextViewText(com.ss.android.article.browser.R.id.desc, ((CharSequence) v1_3));
                        v5.setTextViewText(com.ss.android.article.browser.R.id.a2e, ((CharSequence) v3));
                        v5.setTextViewText(com.ss.android.article.browser.R.id.title, ((CharSequence) v0_2));
                        v5.setImageViewBitmap(com.ss.android.article.browser.R.id.a78, arg10);
                        v2.setContentTitle(((CharSequence) v0_2)).setContentText(((CharSequence) v1_3));
                        v1_2 = v2.build();
                        if (Build.VERSION.SDK_INT >= 16) {
                            v1_2.bigContentView = v4_1;
                        }

                        v1_2.contentView = v5;
                        break;
                    }
                    case 22: {
                        v0_2 = arg9.e;
                        v1_3 = arg9.d;
                        v3 = arg8.getString(com.ss.android.article.browser.R.string.dt) + " · " + new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis()));
                        v4_1 = new RemoteViews(arg8.getPackageName(), R.layout.gs);
                        v4_1.setTextViewText(com.ss.android.article.browser.R.id.desc, ((CharSequence) v1_3));
                        v4_1.setTextViewText(com.ss.android.article.browser.R.id.title, ((CharSequence) v0_2));
                        v4_1.setTextViewText(com.ss.android.article.browser.R.id.a2e, ((CharSequence) v3));
                        v4_1.setImageViewBitmap(com.ss.android.article.browser.R.id.a78, arg10);
                        v2.setContentTitle(((CharSequence) v0_2)).setContentText(((CharSequence) v1_3));
                        v1_2 = v2.build();
                        v1_2.contentView = v4_1;
                        break;
                    }
                    default:
                        v1_2 = android.support.design.a.a(v2, arg8, arg9.e, arg9.d);
                        break;
                }
            }

            if ((arg9.q) && !arg9.a()) {
                v1_2.defaults |= 1;
            }

            if (!arg9.r) {
                return v1_2;
            }

            if (arg9.a()) {
                return v1_2;
            }

            try {
                Object v0_4 = arg8.getSystemService(Context.AUDIO_SERVICE);
                if (Logger.debug()) {
                    Logger.d("MessageShowHandler", "getRingerMode = " + ((AudioManager) v0_4).getRingerMode());
                }

                switch (((AudioManager) v0_4).getRingerMode()) {
                    case 1:
                    case 2: {
                        break;
                    }
                    default:
                        return v1_2;
                }
                if (Logger.debug()) {
                    Logger.d("MessageShowHandler", "set DEFAULT_VIBRATE ");
                }
                v1_2.defaults |= 2;
            } catch (Throwable v0_3) {
                try {
                    v0_3.printStackTrace();
                } catch (Exception v0_1) {
                    label_78:
                    v0_1.printStackTrace();
                    Notification v0_5 = null;
                    return v0_5;
                }
            }
        } catch (Exception v0_1) {
            v0_1.printStackTrace();
        }

        return v1_2;
    }

    private static boolean a(h arg8, Builder arg9) {
        boolean v0 = true;
        int v2 = com.ss.android.newmedia.message.c.a().i > 0 ? 1 : 0;
        if (v2 != 0 && arg8 != null && arg8.t != null && arg8.t.a != null && !arg8.a()) {
            try {
                v2 = arg8.t.b;
                Logger.d("MessageShowHandler", "updateStickTopStyle: stick_top = " + v2);
                if (v2 > 0) {
                    arg9.setPriority(2);
                    if (Build.VERSION.SDK_INT >= 19) {
                        arg9.setWhen((((long) v2)) * 86400000 + System.currentTimeMillis());
                        arg9.setShowWhen(false);
                        return v0;
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            } catch (Throwable v0_1) {
                v0_1.printStackTrace();
            }

            v0 = false;
        } else {
            v0 = false;
        }

        return v0;
    }

    static Map a() {
        return i.h;
    }

    static void a(Context arg12, int arg13, BaseAppData arg14) {
        Object v0_3;
        int v1_1;
        long v4 = 259200;
        long v2 = 600;
        int v6 = 10;
        Iterator v1 = i.d.iterator();
        while (v1.hasNext()) {
            if (((i.a) v1.next()).a != arg13) {
                continue;
            }

            v1.remove();
        }

        int v7 = ((MediaAppData) arg14).mKeepNotifyCount;
        int v8 = ((MediaAppData) arg14).mMaxNotifyCount;
        long v0 = ((long) ((MediaAppData) arg14).mNotifyRefreshPeriod);
        if (v8 <= 0) {
            v8 = 5;
        } else if (v8 > v6) {
            v8 = v6;
        }

        if (v7 <= 0) {
            v6 = 2;
        } else if (v7 <= v6) {
            v6 = v7;
        }

        if (v0 <= 0) {
            v0 = 1800;
        } else if (v0 < v2) {
            v0 = v2;
        } else if (v0 > v4) {
            v0 = v4;
        }

        v2 = 1000 * v0;
        int v4_1 = v6 - 1;
        int v5 = v8 - 1;
        long v6_1 = System.currentTimeMillis();
        try {
            int v0_2 = i.d.size();
            if (v0_2 <= v4_1) {
            } else {
                Collections.sort(i.d, i.g);
                v1_1 = v0_2 - 1;
                while (true) {
                    if (v1_1 < v4_1) {
                        break;
                    }

                    v0_3 = i.d.get(v1_1);
                    if (v6_1 - ((a) v0_3).b <= v2 && v1_1 < v5) {
                        break;
                    }

                    i.d.remove(v1_1);
                    try {
                        Logger.i("MessageShowHandler", "cancel notify " + ((a) v0_3).a);
                        i.c.cancel("app_notify", ((a) v0_3).a);
                    } catch (Exception e) {
                    }
                    --v1_1;
                    continue;
                }
            }
        } catch (Exception v0_1) {
            Logger.w("MessageShowHandler", "check notify list exception: " + v0_1);
        }


        i.d.add(new a(arg13, v6_1));
        try {
            JSONArray v1_2 = new JSONArray();
            Iterator v2_1 = i.d.iterator();
            while (v2_1.hasNext()) {
                v0_3 = v2_1.next();
                JSONObject v3 = new JSONObject();
                v3.put("id", ((a) v0_3).a);
                v3.put("time", ((a) v0_3).b);
                v1_2.put(v3);
            }

            new i$c(arg12, (byte) 0).execute(new String[]{v1_2.toString()});
            return;
        } catch (Exception v0_1) {
        }
    }

    static void a(Context arg0, BaseAppData arg1, Bitmap arg2, h arg3) {
        i.b(arg0, arg1, arg2, arg3);
    }

    static void a(Context arg0, BaseAppData arg1, h arg2, Bitmap arg3) {
        i.b(arg0, arg1, arg2, arg3);
    }

    static void a(Context arg3, String arg4) {
        Object v1 = i.b;
        synchronized (v1) {
            SharedPreferences.Editor v0_1 = arg3.getSharedPreferences("app_notify_info", 0).edit();
            v0_1.putString("notify_list", arg4);
            v0_1.commit();
        }
    }

    private static boolean a(String arg2, BaseAppData arg3) {
        boolean v0 = false;
        if (!android.support.design.a.isTextEmpty(arg2)) {
            try {
                v0 = arg3.c(arg2);
            } catch (Exception v1) {
            }
        }

        return v0;
    }

    private static boolean a(int arg4, Context arg5, Intent arg6) {
        boolean v0 = true;
        if (arg4 == 0) {
            try {
                arg6.putExtra("msg_from", 1);
                arg5.startActivity(arg6);
            } catch (Exception v0_1) {
                v0_1.printStackTrace();
                v0 = false;
            }
        } else {
            v0 = false;
        }

        return v0;
    }

    private static void b(Context arg18, BaseAppData arg19, Bitmap arg20, h arg21) {
        boolean v4_2;
        boolean v5_4;
        n v15_1;
        boolean v14_1 = false;
        int v8_1;
        int v12_1 = 0;
        JSONObject v6_2;
        OppoPushWindowManager v10_1 = null;
        int v14;
        String v13;
        String v12;
        String v11;
        e v10;
        String v5_3;
        String v6_1 = null;
        CharSequence v5_2;
        String v8;
        int v5_1;
        Object v4_1;
        Notification v9;
        Intent v7;
        Log.d("MessageShowHandler", "showWithNotification() called with: context = [" + arg18 + "], appData = [" + arg19 + "], pushBitmap = [" + arg20 + "], messageEntity = [" + arg21 + "]");
        arg18.getPackageName();
        if (arg21 != null) {
            try {
                v7 = i.c(arg18, arg19, arg21);
                if (v7 == null) {
                    return;
                }

                v7.putExtra("msg_from", 1);
                if (i.a(arg21.b, arg18, v7)) {
                    return;
                }

                v9 = i.a(arg18, arg21, arg20);
                if (v9 == null) {
                    return;
                }
                if (arg21.t.d) {
                    if (Build.VERSION.SDK_INT >= 16) {
                        v9.priority = 1;
                    }
                    v9.fullScreenIntent = PendingIntent.getActivity(arg18, arg21.i, new Intent(), 134217728);
                }

                v9.contentIntent = PendingIntent.getActivity(arg18, arg21.i, v7, 134217728);
                v9.deleteIntent = PendingIntent.getService(arg18, arg21.i,
                        new Intent("com.ss.android.newmedia.message.notify.delete.action",
                                ContentUris.withAppendedId(MessageHandler.a, ((long) arg21.i)),
                                arg18, MessageHandler.class), 134217728);
                v4_1 = com.ss.android.newmedia.message.b.a(arg18).a.a(Integer.valueOf(arg21.i));
                if (v4_1 != null) {
                    ++((com.ss.android.newmedia.message.b.a) v4_1).h;
                    ((com.ss.android.newmedia.message.b.a) v4_1).g = System.currentTimeMillis() / 1000;
                }

                com.ss.android.newmedia.message.a.e.a(arg18);
                if (!com.ss.android.newmedia.message.a.e.b()) {
                } else if (!com.ss.android.newmedia.message.a.e.a(arg18).a()) {
                } else {
                    if (arg21.h != 0) {
                        v5_1 = 1;
                    } else {
                        v5_1 = 0;
                    }
                    if (v5_1 == 0) {
                    } else if (arg21.a() && v4_1 != null && ((com.ss.android.newmedia.message.b.a) v4_1).j || !arg21.a()) {
                        label_112:
                        v8 = new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date());
                        CharSequence v6 = null;
                        v5_2 = null;
                        if (arg21.h == 2) {
                            v6_1 = arg21.f;
                        } else {
                            if (arg21.h == 1) {
                                v5_3 = arg21.f;
                            } else {
                                v6_1 = "";
                                v5_3 = "";
                            }
                        }

                        if (v4_1 != null) {
                            ++((com.ss.android.newmedia.message.b.a) v4_1).i;
                        }

                        v10 = com.ss.android.newmedia.message.a.e.a(arg18);
                        v11 = arg21.e;
                        v12 = arg21.d;
                        v13 = v7.toUri(0);
                        v14 = arg21.i;
                        com.ss.android.newmedia.message.c.a();
                        com.ss.android.newmedia.message.c.f();
                        Intent v15 = new Intent();
                        if (!TextUtils.isEmpty(((CharSequence) v6_1))) {
                            v15.putExtra("small_image_url", v6_1);
                        }

                        if (!TextUtils.isEmpty(((CharSequence) v11))) {
                            v15.putExtra("title", v11);
                        }

                        if (!TextUtils.isEmpty(((CharSequence) v8))) {
                            v15.putExtra("time", v8);
                        }

                        if (!TextUtils.isEmpty(((CharSequence) v12))) {
                            v15.putExtra("text", v12);
                        }

                        if (!TextUtils.isEmpty(v5_2)) {
                            v15.putExtra("big_image_url", ((String) v5_2));
                        }

                        if (!TextUtils.isEmpty(((CharSequence) v13))) {
                            v15.putExtra("open_intent", v13);
                        }

                        v15.putExtra("notification_id", v14);
                        com.ss.android.newmedia.message.a.a.a(v10.a, v15);
                    }
                }


                if (v4_1 != null) {
                    com.ss.android.newmedia.message.b.a(arg18).b();
                }
                label_176:
                if (!OppoPushWindowManager.a(arg18).b()) {
                } else if (arg21.v) {
                } else {
                    v10_1 = OppoPushWindowManager.a(arg18);
                    v6_2 = arg21.a;
                    v11 = arg21.d;
                    v12_1 = arg21.i;
                    v8_1 = arg21.x;
                    v13 = arg21.y;
                    v14_1 = arg21.u;
                    v15_1 = new n(arg18, v7);
                    if (!v10_1.b()) {
                    } else if (!v10_1.m) {
                        v4_1 = v10_1.d.getSystemService(Context.POWER_SERVICE);
                        v5_4 = ((PowerManager) v4_1).isScreenOn();
                        if (Build.VERSION.SDK_INT >= 20) {
                            v4_2 = ((PowerManager) v4_1).isInteractive();
                        } else {
                            v4_2 = v5_4;
                        }

                        if (!v4_2) {
                            v10_1.a(v6_2.toString(), v8_1, v13);
                        } else {
                            if (v10_1.c == null) {
                                v10_1.c = LayoutInflater.from(v10_1.d).inflate(com.ss.android.article.browser.R.layout.fk, null);
                            }
                            View v13_1 = v10_1.c.findViewById(com.ss.android.article.browser.R.id.a2b);
                            View v4_3 = v10_1.c.findViewById(com.ss.android.article.browser.R.id.a2a);
                            View v5_5 = v10_1.c.findViewById(com.ss.android.article.browser.R.id.a2d);
                            View v6_3 = v10_1.c.findViewById(com.ss.android.article.browser.R.id.a2f);
                            View v7_1 = v10_1.c.findViewById(com.ss.android.article.browser.R.id.a2e);
                            View v8_2 = v10_1.c.findViewById(com.ss.android.article.browser.R.id.a2c);
                            ((TextView) v5_5).setText(v10_1.d.getString(com.ss.android.article.browser.R.string.app_name));
                            ((TextView) v6_3).setText(((CharSequence) v11));
                            ((ImageView) v8_2).setImageResource(com.ss.android.article.browser.R.drawable.icon);
                            ((TextView) v7_1).setText(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis())));
                            v10_1.b = new WindowManager.LayoutParams();
                            v10_1.b.height = -2;
                            v10_1.b.width = -1;
                            v10_1.b.format = -3;
                            v10_1.b.windowAnimations = 16973828;
                            v10_1.b.type = v10_1.g;
                            v10_1.b.flags = v10_1.h;
                            v10_1.b.setTitle("Toast");
                            v10_1.b.gravity = 49;
                            v10_1.o = 0;
                            ((PushWindowScrollView) v4_3).setOnScrollListener(new com.ss.android.push.window.oppo.e(v10_1));
                            v13_1.setOnTouchListener(new com.ss.android.push.window.oppo.j(new GestureDetector(v10_1.d, new com.ss.android.push.window.oppo.h(v10_1, v12_1, v14_1, ((View.OnClickListener) v15_1)))));
                            m v4_4 = m.a(v10_1.d);
                            if (!OppoPushWindowManager.a(v4_4.a).k) {
                                v4_4.b.a();
                            } else if (v12_1 > 0) {
                                v4_4.b.a(Integer.valueOf(v12_1));
                                v4_4.a();
                            }
                            v10_1.a.removeView(v10_1.c);
                            v10_1.c.setTranslationY(0f);
                            v10_1.a.addView(v10_1.c, v10_1.b);
                            v10_1.m = true;
                            v10_1.e.removeCallbacks(v10_1.p);
                            if (v10_1.l) {
                                v10_1.e.postDelayed(v10_1.p, ((long) v10_1.i));
                            }
                            OppoPushWindowManager.a("pop_window_show", ((long) v12_1), v14_1, new JSONObject[0]);
                        }
                    } else {
                        v10_1.a(v6_2.toString(), v8_1, v13);
                    }
                }
            } catch (Throwable v4) {
                if (Logger.debug()) {
                    v4.printStackTrace();
                }

                v10_1.m = false;

                try {
                    JSONObject v5_6 = new JSONObject();
                    v5_6.put("error", v4.getMessage());
                    OppoPushWindowManager.a("pop_window_show_fail", ((long) v12_1), v14_1, new JSONObject[]{v5_6});
                    v10_1.c();
                } catch (JSONException v4_5) {
                    v4_5.printStackTrace();
                }

                Log.w("MessageShowHandler", "can not get launch intent: " + v4);
                new StringBuilder("can not get launch intent: ").append(v4);
                l.a();
                return;
            }

            try {
                i.c.notify("app_notify", arg21.i, v9);
                i.a(arg18, "news_notify_show", ((long) arg21.i), -1, arg21.u, new JSONObject[0]);
            } catch (Exception v4) {
                new StringBuilder("notify exception: ").append(v4);
                l.a();
            }
        }
    }

    private static void b(Context arg2, BaseAppData arg3, h arg4, Bitmap arg5) {
        i.f.post(new com.ss.android.newmedia.message.m(arg4, arg2, arg3, arg5));
    }

    static boolean b(Context arg1, BaseAppData arg2, h arg3) {
        return i.d(arg1, arg2, arg3);
    }

    private static Intent c(Context arg9, BaseAppData arg10, h arg11) {
        Intent v0 = null;
        if (!android.support.design.a.isTextEmpty(arg11.m)) {
            Uri v0_1 = Uri.parse(arg11.m);
            String v2_1 = v0_1.getScheme();
            String v1 = v0_1.getHost();
            if (("sslocal".equals(v2_1)) && ("webview".equals(v1))) {
                v0 = AdsAppBaseActivity.a(arg9, v0_1);
            } else {
                if ("sslocal".equals(v2_1)) {
                    arg11.m = AdsAppBaseActivity.b(arg11.m);
                    v0_1 = Uri.parse(arg11.m);
                }
                Intent v1_1 = new Intent();
                v1_1.setAction("android.intent.action.VIEW");
                if (AdsAppBaseActivity.c(v2_1)) {
                    v1_1.putExtra("is_from_self", true);
                }
                v1_1.setData(v0_1);
                arg10.a(arg11.m, arg11.n);
                v0 = v1_1;
            }
        } else if (arg11.o != null) {
            int v2 = arg11.o.optInt("t", 0);
            int v3 = arg11.o.optInt("p", 0);
            long v6 = arg11.o.optLong("uid", 0);
            v0 = arg10.a(arg9, v2, v3, arg11.o, arg11.n);
            if (v0 != null && (android.support.design.a.isTextEmpty(v0.getDataString()))) {
                v0.setData(Uri.parse("ssnotify://common/" + v2 + v3 + v6));
            }
        }

        if (v0 == null) {
            v0 = ToolUtils.getLaunchIntentForPackage(arg9, arg9.getPackageName());
        } else {
            v0.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            v0.putExtra("from_notification", true);
            v0.putExtra("notification_image_type", arg11.g);
            v0.putExtra("msg_from", 1);
            v0.putExtra("msg_id", arg11.i);
            v0.putExtra("message_from", arg11.x);
            v0.putExtra("is_strong_message", arg11.t.a.a);
            v0.putExtra("msg_post_back", arg11.s);
            if (!android.support.design.a.isTextEmpty(arg11.y)) {
                v0.putExtra("message_extra", arg11.y);
            }
        }

        return v0;
    }

    private static boolean d(Context arg7, BaseAppData arg8, h arg9) {
        boolean v2_2;
        boolean v0 = false;
        if (arg8 != null) {
            Activity v2 = arg8.aO();
            if (v2 == null) {
                return v0;
            }

            if ((v2 instanceof AbsSplashActivity)) {
                return v0;
            }

            if (arg9.l > 0) {
                return v0;
            }

            if (android.support.design.a.d(v2.getWindow().getDecorView())) {
                return v0;
            }

            if (!w.a(arg7).c && !arg9.t.a.a && ((v2.getClass().getName().contains("Detail")) || (v2.getClass().getName().contains("AnswerListActivity")))) {
                arg9.w = true;
                return v0;
            }

            arg7.getPackageName();
            if (android.support.design.a.isTextEmpty(arg9.e)) {
                arg9.e = arg7.getString(com.ss.android.article.browser.R.string.dt);
            }

            new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date(System.currentTimeMillis()));
            try {
                String v2_1 = arg9.m;
                if (arg8 != null) {
                    v2_2 = arg8.a(v2_1);
                } else {
                    v2_2 = true;
                }
                if (!v2_2) {
                    return v0;
                }

                Intent v2_3 = i.c(arg7, arg8, arg9);
                if (v2_3 == null) {
                    return v0;
                }

                v2_3.putExtra("msg_from", 2);
                if (i.a(arg9.b, arg7, v2_3)) {
                    return true;
                }

                v0 = android.support.design.a.a(arg9, v2_3);
            } catch (Exception v1) {
                Log.w("MessageShowHandler", "can not get launch intent: " + v1);
                new StringBuilder("can not get launch intent: ").append(v1);
                l.a();
            }
        }
        return v0;
    }

    static final class a {
        public int a;
        public long b;

        public a(int arg1, long arg2) {

            this.a = arg1;
            this.b = arg2;
        }
    }

    public static final class b extends ImageView {
        private final Context a;
        private final BaseAppData b;
        private final h c;

        public b(Context arg1, BaseAppData arg2, h arg3) {
            super(arg1);
            this.a = arg1;
            this.b = arg2;
            this.c = arg3;
        }

        public final void setImageBitmap(Bitmap arg4) {
            if (Logger.debug()) {
                String v1 = "MessageShowHandler";
                StringBuilder v2 = new StringBuilder("get PushImageView Bitmap imageType = ").append(this.c.g).append(" bm = ");
                String v0 = arg4 == null ? "null" : arg4.toString();
                Logger.d(v1, v2.append(v0).append("locktype  = ").append(this.c.h).toString());
            }

            i.a().remove(Integer.valueOf(this.c.i));
            i.a(this.a, this.b, arg4, this.c);
        }

        public final void setImageDrawable(Drawable arg2) {
            this.setImageBitmap(null);
        }
    }

    static final class i$c extends AsyncTask {
        private Context a;

        i$c(Context arg1, byte arg2) {
            this(arg1);
        }

        private i$c(Context arg1) {

            this.a = arg1;
        }

        private Void a(String[] arg4) {
            Void v2 = null;
            try {
                if (this.a == null) {
                    return v2;
                }

                if (arg4 == null) {
                    return v2;
                }

                if (arg4.length <= 0) {
                    return v2;
                }

                i.a(this.a, arg4[0]);
            } catch (Exception v0) {
            }

            return v2;
        }

        protected final Object doInBackground(Object[] arg2) {
            return this.a(((String[]) arg2));
        }
    }

    static final class i$d extends AsyncTask {
        i$d() {

        }

        private static Void a(String[] arg8) {
            Void v7 = null;
            if (arg8 != null && arg8.length > 0) {
                try {
                    String v0_1 = arg8[0];
                    String v1 = arg8[1];
                    String v2 = arg8[2];
                    String v3 = arg8[3];
                    if (TextUtils.isEmpty(((CharSequence) v0_1))) {
                        return v7;
                    }

                    if (Logger.debug()) {
                        Logger.d("MessageShowHandler", "callback_url = " + v0_1);
                    }

                    JSONObject v4 = new JSONObject();
                    if (!TextUtils.isEmpty(((CharSequence) v1))) {
                        v4.put("did", v1);
                    }

                    if (!TextUtils.isEmpty(((CharSequence) v2))) {
                        v4.put("id", v2);
                    }

                    if (!TextUtils.isEmpty(((CharSequence) v3))) {
                        v4.put("url", v3);
                    }

                    if (!AbsApiThread.isApiSuccess(new JSONObject(NetworkUtils.executePost(-1, v0_1, v4.toString().getBytes("UTF-8"), NetworkUtils.CompressType.GZIP, "application/json; charset=utf-8")))) {
                        return v7;
                    }

                    if (!Logger.debug()) {
                        return v7;
                    }

                    Logger.d("MessageShowHandler", "send callback " + v4.toString() + " Success");
                } catch (Throwable v0) {
                }
            }

            return v7;
        }

        protected final Object doInBackground(Object[] arg2) {
            return i$d.a(((String[]) arg2));
        }
    }
}

